﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json;
using ZHDJ.Data.Models.Center;
using ZHDJ.Data.Models.Edu;
using ZHDJ.WebPage.Master;

namespace ZHDJ.Web.Portal.MessageBox
{
    public partial class PartyMessageBoxMore : UseMorePageMasterPage
    {
        /// <summary>
        /// 页数
        /// </summary>
        private string PageIndex
        {
            get
            {
                return this.Request["PageIndex"] ?? "";
            }
        }

        /// <summary>
        /// 每页条数
        /// </summary>
        private string PageSize
        {
            get
            {
                return this.Request["PageSize"] ?? "";
            }
        }
        /// <summary>
        /// 查询标题
        /// </summary>
        private string QueryText
        {
            get
            {
                return this.Request["QueryText"] ?? "";
            }
        }

        /// <summary>
        /// 状态
        /// </summary>
        private string Status
        {
            get
            {
                return this.Request["Status"] ?? "";
            }
        }

        /// <summary>
        /// 
        /// </summary>
        private string DataCount
        {
            get
            {
                return this.Request["DataCount"] ?? "";
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                LoadData();
            }

            if (!string.IsNullOrEmpty(this.PageIndex))
            {
                this.WriteList();
            }

          
            else if (!string.IsNullOrEmpty(this.DataCount))
            {
                WriteDataCount();
            }
           
        }
        public void LoadData()
        {

        }

        private void WriteList()
        {
            StringBuilder sbHtml = new StringBuilder();
            
            DataTable dt =
                PartyMessageBox.GetGridData(Convert.ToInt32(this.PageIndex), Convert.ToInt32(PageSize), QueryText, Status, true).Tables[0];

            dt.Columns.Add("CreateTimeEx", typeof (string));
            dt.Columns.Add("ReplyTimeEx", typeof (string));
            dt.Columns["ReplyTimeEx"].DefaultValue = "";
            dt.Columns["CreateTimeEx"].DefaultValue = "";
            foreach (DataRow dr in dt.Rows)
            {
                dr["CreateTimeEx"] = Convert.ToDateTime(dr["CreateTime"]).ToString("yyyy-MM-dd HH:mm");
                if (Convert.ToInt32(dr["Status"]) == 4)
                {
                    dr["ReplyTimeEx"] = Convert.ToDateTime(dr["ReplyTime"]).ToString("yyyy-MM-dd HH:mm");
                }

            }
            var json = JsonConvert.SerializeObject(dt);
            Response.Clear();
            Response.Write(json);
            Response.End();
        }

        private void WriteDataCount()
        {
            Response.Clear();
            Response.Write(PartyMessageBox.GetGridData(0,10, QueryText, Status, true).Tables[0]);
            Response.End();
        }
        #region 模块菜单
        /// <summary>
        /// 初始化module  如果通过url传参可不设置
        /// </summary>
        protected override void InitModule()
        {
            Module = "MessageBox";
            //Category = "";

        }
        #endregion
    }
}